package com.ruoyi.web.controller.projectcreate;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.ProCreateBuilding;
import com.ruoyi.system.service.IProCreateBuildingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 创建项目Controller
 *
 * @author ruoyi
 * @date 2020-06-17
 */
@Controller

@RequestMapping("/system/building")
public class ProCreateBuildingController extends BaseController {
    private String prefix = "system/building";

    @Autowired
    private IProCreateBuildingService proCreateBuildingService;

    @RequiresPermissions("system:building:view")
    @GetMapping()
    public String building() {
        return prefix + "/building";
    }

    /**
     * 查询创建项目列表
     */
    @RequiresPermissions("system:building:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProCreateBuilding proCreateBuilding) {
        startPage();
        List<ProCreateBuilding> list = proCreateBuildingService.selectProCreateBuildingList(proCreateBuilding);
        return getDataTable(list);
    }

    /**
     * 导出创建项目列表
     */
    @RequiresPermissions("system:building:export")
    @Log(title = "创建项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProCreateBuilding proCreateBuilding) {
        List<ProCreateBuilding> list = proCreateBuildingService.selectProCreateBuildingList(proCreateBuilding);
        ExcelUtil<ProCreateBuilding> util = new ExcelUtil<ProCreateBuilding>(ProCreateBuilding.class);
        return util.exportExcel(list, "building");
    }

    /**
     * 新增创建项目
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存创建项目
     */
    @RequiresPermissions("system:building:add")
    @Log(title = "创建项目", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProCreateBuilding proCreateBuilding) {
        proCreateBuilding.setpFounder(ShiroUtils.getLoginName());
        return toAjax(proCreateBuildingService.insertProCreateBuilding(proCreateBuilding));
    }

    /**
     * 修改创建项目
     */
    @GetMapping("/edit/{pId}")
    public String edit(@PathVariable("pId") Integer pId, ModelMap mmap) {
        ProCreateBuilding proCreateBuilding = proCreateBuildingService.selectProCreateBuildingById(pId);
        mmap.put("proCreateBuilding", proCreateBuilding);
        return prefix + "/edit";
    }

    /**
     * 修改保存创建项目
     */
    @RequiresPermissions("system:building:edit")
    @Log(title = "创建项目", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProCreateBuilding proCreateBuilding) {
        proCreateBuilding.setpFounder(ShiroUtils.getLoginName());

        return toAjax(proCreateBuildingService.updateProCreateBuilding(proCreateBuilding));
    }

    /**
     * 删除创建项目
     */
    @RequiresPermissions("system:building:remove")
    @Log(title = "创建项目", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(proCreateBuildingService.deleteProCreateBuildingByIds(ids));
    }

    /**
     * 表格细节视图
     */
    @GetMapping("/detail/{bId}")
    public String detail(@PathVariable("bId") int bId, ModelMap map) {
        ProCreateBuilding proCreateBuilding = proCreateBuildingService.selectProCreateBuildingById(bId);
        map.put("proCreateBuilding", proCreateBuilding);
        return prefix + "/detail";
    }
}
